package org.example.network.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

public class Client01 {
    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("localhost" , 8888);

        System.out.println("客户端启动了!");


        PrintStream  printStream = new PrintStream(socket.getOutputStream());

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        String line = null;

        while( (line = bufferedReader.readLine()) != null ){

            printStream.println(line);
            printStream.flush();
        }

        // 读取任意时刻服务器发送过来的数据
        BufferedReader bufferedReader1 = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        String line1 = null;

        while( (line1 = bufferedReader1.readLine()) != null ){

            System.out.println(line1);
        }

    }
}
